#include <QtGui/QApplication>
#include <QtGui/QPushButton>
#include <QtCore/QStateMachine>
#include <QtCore/QState>
#include <QtCore/QFinalState>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QPushButton button("Ok");

    /* The state machine. */
    QStateMachine machine;

    /* Three states to the state machine. */
    QState s1;
    QState s2;
    QState s3;

    /* For each state it sets the button's text property. */
    s1.setPropertyOnEntry(&button, "text", "In state S[1]");
    s2.setPropertyOnEntry(&button, "text", "In state S[2]");
    s3.setPropertyOnEntry(&button, "text", "In state S[3]");

    /* Adds the transitions to each state */
    s1.addTransition(&button, SIGNAL(clicked()), &s2);
    s2.addTransition(&button, SIGNAL(clicked()), &s3);
    s3.addTransition(&button, SIGNAL(clicked()), &s1);

    /* Adds the three states s1, s2 and s3 to the state machine. */
    machine.addState(&s1);
    machine.addState(&s2);
    machine.addState(&s3);

    /* Sets the state s1 as initial state. */
    machine.setInitialState(&s1);

    /* Starts the state machine. */
    machine.start();

    button.show();

    return a.exec();
}
